﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Financeiro.Model;

namespace Financeiro
{
    public partial class Contas : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            atualizarGrids();
        }

        protected void atualizarGrids()
        {
            DataTable charges_grid = ContasModel.listContas(0);
            DataTable debts_grid = ContasModel.listContas(1);

            valorSaldo.Text = ContasModel.getSaldo().ToString();

            gridContasReceber.DataSource = charges_grid;
            gridContasPagar.DataSource = debts_grid;
            gridContasReceber.DataBind();
            gridContasPagar.DataBind();
        }

        protected void gridContasPagar_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
                e.Row.Attributes.Add("style", "cursor:pointer;");
                //e.Row.Attributes.Add("onclick", "location='CriarConta.aspx?id=" + e.Row.Cells[0].Text + "'");
                DataRowView rowView = (DataRowView)e.Row.DataItem;

                // Retrieve the state value for the current row. 
                String id_conta = rowView["id_conta"].ToString();

                int status = Convert.ToInt32(rowView["status"]);
                if (status != 1)
                {
                    e.Row.Attributes.Add("onclick", "location='ContaDetalhe.aspx?id=" + id_conta + "'");
                }
                else
                {

                    e.Row.Attributes.Add("style", "cursor:mouse;");
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=''");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
                }
            }
        }

        protected void gridContasReceber_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
                e.Row.Attributes.Add("style", "cursor:pointer;");
                //e.Row.Attributes.Add("onclick", "location='CriarConta.aspx?id=" + e.Row.Cells[0].Text + "'");
                DataRowView rowView = (DataRowView)e.Row.DataItem;

                // Retrieve the state value for the current row. 
                String id_conta = rowView["id_conta"].ToString();

                int status = Convert.ToInt32(rowView["status"]);
                if (status == 1)
                {
                    e.Row.Attributes.Add("onclick", "location='NotaFiscal.aspx?&id=" + id_conta + "'");
                }
                else
                {
                    e.Row.Attributes.Add("onclick", "location='ContaDetalhe.aspx?id=" + id_conta + "'");
                }
            }
        }

        protected void btnCriarConta_Click(object sender, EventArgs e)
        {
            Response.Redirect("/CriarConta.aspx");
        }

        protected void btnTeste_Click(object sender, EventArgs e)
        {
			//ContasModel.solicitaCota(30); //TESTE PARA ATENDIMENTO de ID 1 = 19/03/2011 10:00:00, Id 3 = 17/03/2011 10:00:00
			BoletoBancarioModel.testeFuturoWebService(3, new DateTime(2011, 3, 17, 10, 0, 0));
			
            atualizarGrids();
        }
    }
}